home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / server / newitem.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  4KB  |  163 lines

  1.  
  2. /* This containes item logic for client/server.  IT doesn't contain
  3.  * the actual commands that send the data, but does contain
  4.  * the logic for what items should be sent.
  5.  */
  6.  
  7.  
  8. #include <global.h>
  9. #include <object.h>    /* LOOK_OBJ */
  10. #include <newclient.h>
  11.  
  12. enum {a_none, a_readied, a_wielded, a_worn, a_active, a_applied};
  13. #if 0
  14. static char *apple_string[] = {
  15.     "", " (readied)", " (wielded)", " (worn)", " (active)", " (applied)"
  16. };
  17. #endif
  18.  
  19. #define F_APPLIED    0x000F
  20. #define F_LOCATION    0x00F0
  21. #define F_CLEAR_INV    0x0100
  22. #define F_UNPAID    0x0200
  23. #define F_MAGIC        0x0400
  24. #define F_CURSED    0x0800
  25. #define F_DAMNED    0x1000
  26. #define F_OPEN        0x2000
  27. #define F_NOPICK    0x4000
  28.  
  29. /* 
  30.  *  This is a similar to query_name, but returns flags
  31.  *  to be sended to client. 
  32.  */
  33. unsigned int query_flags (object *op)
  34. {
  35.     unsigned int flags = 0;
  36.  
  37.     if(QUERY_FLAG(op,FLAG_APPLIED)) {
  38.     switch(op->type) {
  39.       case BOW:
  40.       case WAND:
  41.       case ROD:
  42.       case HORN:
  43.         flags = a_readied;
  44.         break;
  45.       case WEAPON:
  46.         flags = a_wielded;
  47.         break;
  48.       case SKILL:
  49.       case ARMOUR:
  50.       case HELMET:
  51.       case SHIELD:
  52.       case RING:
  53.       case BOOTS:
  54.       case GLOVES:
  55.       case AMULET:
  56.       case GIRDLE:
  57.       case BRACERS:
  58.       case CLOAK:
  59.         flags = a_worn;
  60.         break;
  61.       case CONTAINER:
  62.         flags = a_active;
  63.         break;
  64.       default:
  65.         flags = a_applied;
  66.         break;
  67.     }
  68.     }
  69.     if (op->type == CONTAINER && ((op->env && op->env->container == op) || 
  70.     (!op->env && QUERY_FLAG(op,FLAG_APPLIED))))
  71.     flags |= F_OPEN;
  72.     
  73.     if (QUERY_FLAG(op,FLAG_KNOWN_CURSED)) {
  74.     if(QUERY_FLAG(op,FLAG_DAMNED))
  75.         flags |= F_DAMNED;
  76.     else if(QUERY_FLAG(op,FLAG_CURSED))
  77.         flags |= F_CURSED;
  78.     }
  79.     if (QUERY_FLAG(op,FLAG_KNOWN_MAGICAL) && !QUERY_FLAG(op,FLAG_IDENTIFIED))
  80.     flags |= F_MAGIC;
  81.     if (QUERY_FLAG(op,FLAG_UNPAID))
  82.     flags |= F_UNPAID;
  83.  
  84.     return flags;
  85. }
  86.  
  87. void esrv_draw_look(object *pl)
  88. {
  89. #if ERICSERVER
  90.     object *tmp, *last;
  91.     int flags, clear = F_CLEAR_INV; /* deletes old items in look window */
  92.  
  93.   if(QUERY_FLAG(pl, FLAG_REMOVED) || pl->map == NULL ||
  94.     pl->map->in_memory != MAP_IN_MEMORY || out_of_map(pl->map,pl->x,pl->y))
  95.     return;
  96.  
  97.  
  98.     for (tmp=get_map_ob(pl->map,pl->x,pl->y); tmp && tmp->above;tmp=tmp->above)
  99.     ; 
  100.  
  101.     esrv_new_location (0);    /* ground */
  102.  
  103.     for (last=NULL; tmp!=last; tmp=tmp->below) {
  104.     if (QUERY_FLAG(tmp, FLAG_IS_FLOOR) && !last) {
  105.         last = tmp->below;  /* assumes double floor mode */
  106.         if (last && QUERY_FLAG(last, FLAG_IS_FLOOR))
  107.         last = last->below;
  108.     }
  109.     if (LOOK_OBJ(tmp)) {
  110.         flags = query_flags (tmp);
  111.         flags |= clear;
  112.         if (QUERY_FLAG(tmp, FLAG_NO_PICK))
  113.         flags |=  F_NOPICK;
  114.         esrv_add_item (pl->contr->eric_server, tmp->count, flags,
  115.                QUERY_FLAG(tmp, FLAG_NO_PICK) ? -1 : tmp->weight,
  116.                tmp->face->number, query_short_name(tmp));
  117.         clear = 0;
  118.     }
  119.     }
  120.     esrv_send_simple_cmd (pl->contr->eric_server, "item");
  121. #endif
  122. }
  123.  
  124. void esrv_send_inventory(object *pl, object *op)
  125. {
  126. #if ERICSERVER
  127.     object *tmp;
  128.     int flags, clear = F_CLEAR_INV; /* deletes old items in look window */
  129.     
  130.     esrv_new_location (op->count);
  131.     
  132.     for (tmp=op->inv; tmp; tmp=tmp->below) {
  133.     if (LOOK_OBJ(tmp)) {
  134.         flags = query_flags (tmp);
  135.         flags |= clear;
  136.         if (QUERY_FLAG(tmp, FLAG_NO_PICK))
  137.         flags |=  F_NOPICK;
  138.         esrv_add_item (pl->contr->eric_server, tmp->count, flags, 
  139.                QUERY_FLAG(tmp, FLAG_NO_PICK) ? -1 : tmp->weight,
  140.                tmp->face->number, query_short_name(tmp));
  141.         clear = 0;
  142.     }
  143.     }
  144.     esrv_send_simple_cmd (pl->contr->eric_server, "item");
  145. #endif
  146. }
  147.  
  148. void esrv_send_item(object *pl, object*op)
  149. {
  150. #if ERICSERVER
  151.     if (! LOOK_OBJ(op)) 
  152.     return;
  153.     if (!op->env) /* tmp. solution to keep items right order in look window */
  154.     esrv_draw_look(pl);
  155.  
  156.     esrv_new_location (op->env ? op->env->count : 0);
  157.     esrv_add_item (pl->contr->eric_server, op->count, query_flags(op), 
  158.            op->weight, op->face->number, query_short_name(op));
  159.     esrv_send_simple_cmd (pl->contr->eric_server, "item");
  160. #endif
  161. }
  162.  
  163.